package pack

import (
	"douyin_mini/cmd/comment/dal/db"
	"douyin_mini/kitex_gen/comment"
)

func Comment(c *db.Comment) *comment.Comment {
	if c == nil {
		return nil
	}
	return &comment.Comment{
		Id:         0,
		Content:    c.Content,
		CreateDate: c.CreatedAt.String(),
	}
}

func Comments(cs []*db.Comment) []*comment.Comment {
	comments := make([]*comment.Comment, 0)
	for _, m := range cs {
		if n := Comment(m); n != nil {
			comments = append(comments, n)
		}
	}
	return comments
}

func UserIds(ms []*db.Comment) []int64 {
	uIds := make([]int64, 0)
	if len(ms) == 0 {
		return uIds
	}
	uIdMap := make(map[int64]struct{})
	for _, m := range ms {
		if m != nil {
			uIdMap[m.UserId] = struct{}{}
		}
	}
	for uId := range uIdMap {
		uIds = append(uIds, uId)
	}
	return uIds
}
